{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1267650600228229401496703205376\n",
      "126765060022822940149670320537\n",
      "12676506002282294014967032053\n",
      "1267650600228229401496703205\n",
      "126765060022822940149670320\n",
      "12676506002282294014967032\n",
      "1267650600228229401496703\n",
      "126765060022822940149670\n",
      "12676506002282294014967\n",
      "1267650600228229401496\n",
      "126765060022822940149\n",
      "12676506002282294014\n",
      "1267650600228229401\n",
      "126765060022822940\n",
      "12676506002282294\n",
      "1267650600228229\n",
      "126765060022822\n",
      "12676506002282\n",
      "1267650600228\n",
      "126765060022\n",
      "12676506002\n",
      "1267650600\n",
      "126765060\n",
      "12676506\n",
      "1267650\n",
      "126765\n",
      "12676\n",
      "1267\n",
      "126\n",
      "12\n",
      "1\n",
      "0\n",
      "出现次数: 5\n"
     ]
    }
   ],
   "source": [
    "num= 2**100\n",
    "print(num)\n",
    "\n",
    "count = 0\n",
    "while   num >  0:\n",
    "    if num % 10 == 6:\n",
    "\n",
    "         count = count + 1\n",
    "    num = num // 10\n",
    "    print(num)\n",
    "print('出现次数:',count)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1267650600228229401496703205376\n",
      "出现次数: 5\n"
     ]
    }
   ],
   "source": [
    "num= 2**100\n",
    "print(num)\n",
    "count = 0\n",
    "for   digit in str(num):\n",
    "    if digit==\"6\":\n",
    "\n",
    "         count = count + 1\n",
    "\n",
    "\n",
    "print('出现次数:',count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "range(0,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(range(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "range(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(range(0,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list1= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "list2= [1, 2, 3, 4]\n",
      "list3= []\n"
     ]
    }
   ],
   "source": [
    "list1= list (range (0,10))\n",
    "print(\"list1=\",list1)\n",
    "\n",
    "list2= list (range (1,5))\n",
    "print(\"list2=\",list2)\n",
    "\n",
    "list3= list (range (0))\n",
    "print(\"list3=\",list3)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list4= [0, 5, 10, 15, 20, 25]\n",
      "list5 [0, 2, 4, 6, 8]\n",
      "list6= [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]\n",
      "list7= []\n"
     ]
    }
   ],
   "source": [
    "list4= list (range (0,30,5))\n",
    "print(\"list4=\",list4)\n",
    "\n",
    "list5= list (range (0,10,2))\n",
    "print(\"list5\",list5)\n",
    "\n",
    "list6= list (range (0,-10,-1))\n",
    "print(\"list6=\",list6)\n",
    "\n",
    "list7= list (range (0))\n",
    "print(\"list7=\",list7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "4\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "for x in  range (3,6):\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "for i in range (3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for x in range(4,10,2):\n",
    "    print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1x1=1  \n",
      "1x2=2  2x2=4  \n",
      "1x3=3  2x3=6  3x3=9  \n",
      "1x4=4  2x4=8  3x4=12 4x4=16 \n",
      "1x5=5  2x5=10 3x5=15 4x5=20 5x5=25 \n",
      "1x6=6  2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 \n",
      "1x7=7  2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 \n",
      "1x8=8  2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 \n",
      "1x9=9  2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 \n"
     ]
    }
   ],
   "source": [
    "for i in range (1,10):\n",
    "     for j in range(1,i+1):\n",
    "          result = j*i\n",
    "          print('%dx%d=%-3d'% (j,i,result),end='')\n",
    "     print()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2**100 is 1267650600228229401496703205376 \n",
      "without 9 is :1267650600228229401496703205376\n"
     ]
    }
   ],
   "source": [
    "num = 2**100\n",
    "without9=''\n",
    "for digit in str (num):\n",
    "    if digit ==9:\n",
    "        pass\n",
    "    else:\n",
    "        without9 += digit\n",
    "print(\"2**100 is %d \\nwithout 9 is :%s\" % (num,without9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2**100 is 1267650600228229401496703205376 \n",
      "without 9 is :12676506002282240146703205376\n"
     ]
    }
   ],
   "source": [
    "num = 2**100\n",
    "without9 = ''\n",
    "for digit in str(num):\n",
    "    if digit == '9':\n",
    "        continue\n",
    "    without9 += digit\n",
    "print(\"2**100 is %d \\nwithout 9 is :%s\"% (num,without9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2**100 is 1267650600228229401496703205376 \n",
      "the position of 9 is Pos.16\n"
     ]
    }
   ],
   "source": [
    "num = 2**100\n",
    "pos=0\n",
    "for digit in str(num):\n",
    "    pos = pos +1\n",
    "    if digit == '9':\n",
    "             break \n",
    "print(\"2**100 is %d \\nthe position of 9 is Pos.%d\"% (num,pos))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2是2~100以内的第1个素数>\n",
      "3是2~100以内的第2个素数>\n",
      "4是2~100以内的第3个素数>\n",
      "5是2~100以内的第4个素数>\n",
      "6是2~100以内的第5个素数>\n",
      "7是2~100以内的第6个素数>\n",
      "8是2~100以内的第7个素数>\n",
      "9是2~100以内的第8个素数>\n",
      "10是2~100以内的第9个素数>\n",
      "11是2~100以内的第10个素数>\n",
      "12是2~100以内的第11个素数>\n",
      "13是2~100以内的第12个素数>\n",
      "14是2~100以内的第13个素数>\n",
      "15是2~100以内的第14个素数>\n",
      "16是2~100以内的第15个素数>\n",
      "17是2~100以内的第16个素数>\n",
      "18是2~100以内的第17个素数>\n",
      "19是2~100以内的第18个素数>\n",
      "20是2~100以内的第19个素数>\n",
      "21是2~100以内的第20个素数>\n",
      "22是2~100以内的第21个素数>\n",
      "23是2~100以内的第22个素数>\n",
      "24是2~100以内的第23个素数>\n",
      "25是2~100以内的第24个素数>\n",
      "26是2~100以内的第25个素数>\n",
      "27是2~100以内的第26个素数>\n",
      "28是2~100以内的第27个素数>\n",
      "29是2~100以内的第28个素数>\n",
      "30是2~100以内的第29个素数>\n",
      "31是2~100以内的第30个素数>\n",
      "32是2~100以内的第31个素数>\n",
      "33是2~100以内的第32个素数>\n",
      "34是2~100以内的第33个素数>\n",
      "35是2~100以内的第34个素数>\n",
      "36是2~100以内的第35个素数>\n",
      "37是2~100以内的第36个素数>\n",
      "38是2~100以内的第37个素数>\n",
      "39是2~100以内的第38个素数>\n",
      "40是2~100以内的第39个素数>\n",
      "41是2~100以内的第40个素数>\n",
      "42是2~100以内的第41个素数>\n",
      "43是2~100以内的第42个素数>\n",
      "44是2~100以内的第43个素数>\n",
      "45是2~100以内的第44个素数>\n",
      "46是2~100以内的第45个素数>\n",
      "47是2~100以内的第46个素数>\n",
      "48是2~100以内的第47个素数>\n",
      "49是2~100以内的第48个素数>\n",
      "50是2~100以内的第49个素数>\n",
      "51是2~100以内的第50个素数>\n",
      "52是2~100以内的第51个素数>\n",
      "53是2~100以内的第52个素数>\n",
      "54是2~100以内的第53个素数>\n",
      "55是2~100以内的第54个素数>\n",
      "56是2~100以内的第55个素数>\n",
      "57是2~100以内的第56个素数>\n",
      "58是2~100以内的第57个素数>\n",
      "59是2~100以内的第58个素数>\n",
      "60是2~100以内的第59个素数>\n",
      "61是2~100以内的第60个素数>\n",
      "62是2~100以内的第61个素数>\n",
      "63是2~100以内的第62个素数>\n",
      "64是2~100以内的第63个素数>\n",
      "65是2~100以内的第64个素数>\n",
      "66是2~100以内的第65个素数>\n",
      "67是2~100以内的第66个素数>\n",
      "68是2~100以内的第67个素数>\n",
      "69是2~100以内的第68个素数>\n",
      "70是2~100以内的第69个素数>\n",
      "71是2~100以内的第70个素数>\n",
      "72是2~100以内的第71个素数>\n",
      "73是2~100以内的第72个素数>\n",
      "74是2~100以内的第73个素数>\n",
      "75是2~100以内的第74个素数>\n",
      "76是2~100以内的第75个素数>\n",
      "77是2~100以内的第76个素数>\n",
      "78是2~100以内的第77个素数>\n",
      "79是2~100以内的第78个素数>\n",
      "80是2~100以内的第79个素数>\n",
      "81是2~100以内的第80个素数>\n",
      "82是2~100以内的第81个素数>\n",
      "83是2~100以内的第82个素数>\n",
      "84是2~100以内的第83个素数>\n",
      "85是2~100以内的第84个素数>\n",
      "86是2~100以内的第85个素数>\n",
      "87是2~100以内的第86个素数>\n",
      "88是2~100以内的第87个素数>\n",
      "89是2~100以内的第88个素数>\n",
      "90是2~100以内的第89个素数>\n",
      "91是2~100以内的第90个素数>\n",
      "92是2~100以内的第91个素数>\n",
      "93是2~100以内的第92个素数>\n",
      "94是2~100以内的第93个素数>\n",
      "95是2~100以内的第94个素数>\n",
      "96是2~100以内的第95个素数>\n",
      "97是2~100以内的第96个素数>\n",
      "98是2~100以内的第97个素数>\n",
      "99是2~100以内的第98个素数>\n",
      "100是2~100以内的第99个素数>\n"
     ]
    }
   ],
   "source": [
    "max = 100\n",
    "cont=0\n",
    "i = 2\n",
    "while (i<= max):\n",
    "    flag = 0\n",
    "    j=2\n",
    "    while (i/j == 0):\n",
    "\n",
    "        if i%j ==0:\n",
    "            flag=1\n",
    "            break\n",
    "        else:\n",
    "            j=j+1\n",
    "    if (flag==0):\n",
    "        cont += 1\n",
    "        print(f\"{i}是2~{max}以内的第{cont}个素数>\")\n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 4, 5, 6, 8, 10, 9, 12, 15]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lst1 = [1,2,3]\n",
    "lst2 = [3,4,5]\n",
    "[x*y for x in lst1 for y in lst2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x for x in lst1 if 4>x>1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[x for x in lst1 if 4>x>2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6的阶乘是： 720\n"
     ]
    }
   ],
   "source": [
    "def fact(n):\n",
    "    result = 1\n",
    "    for i in range(1,n+1):\n",
    "        result = result * i\n",
    "    return result\n",
    "\n",
    "n = input('请输入n值：')\n",
    "print(\"%d的阶乘是：\"% int(n),fact(int(n)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MyMLenvAllinOne",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
